//
//  HosPCommentListViewController.m
//  安好
//
//  Created by lianchuang on 14/12/10.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "HosPCommentListViewController.h"
#import "DocCommentInfoCell.h"
#import "DocCommentListCell.h"

@interface HosPCommentListViewController ()

@end

@implementation HosPCommentListViewController
{
    NSArray *commentsArray;
    NSDictionary *infoDic;
    NSInteger page;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    page=0;
    UIBarButtonItem *backImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backClicked)];
    backImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backImg;
    self.tableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
    [self.view addSubview:self.tableview];
    self.tableview.dataSource=self;
    self.tableview.delegate=self;
    self.tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.navigationItem.title=@"医生评价";
    commentsArray=[[NSArray alloc]init];
    infoDic=[[NSDictionary alloc]init];
    [self loadCommenList];
}
- (void)loadCommenList
{
    [self showActionView];
    NSString * postURL = [NSString stringWithFormat:@"%@wiki/hospitalComment/",kBaseURL];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *select;
    if ([self.type isEqualToString:@"1"]) {
        select=@"hospitalid";
    }else if ([self.type isEqualToString:@"2"])
    {
        select=@"hospdeptid";
    }
    else if ([self.type isEqualToString:@"3"])
    {
        select=@"doctorid";
    }
    NSDictionary *paramers=@{
                             @"platform": kPlatform,
                             @"version":kVersion,
                             @"page":[NSString stringWithFormat:@"%d",page+1],
                             @"type":self.type,
                             select:self.commendid,
                             };
    
    

    [manager POST:postURL parameters:paramers success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self hiddenActionView];
        NSString *status=[NSString stringWithFormat:@"%@",[responseObject valueForKey:@"status"]];
        if ([status isEqualToString:@"1"]) {
            commentsArray=[[responseObject valueForKey:@"data"] valueForKey:@"commentdata"];
            infoDic=[responseObject valueForKey:@"data"];
            [self.tableview reloadData];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hiddenActionView];
        [self shouLabel:@"暂无内容"];
    }];
    
}
#pragma mark UItableviewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else
    {
        return 0;
        return commentsArray.count;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        static NSString *indentifier=@"commentInfo";
        DocCommentInfoCell *infoCell=[tableView dequeueReusableCellWithIdentifier:indentifier];
        if (!infoCell) {
            infoCell=[[[NSBundle mainBundle]loadNibNamed:@"DocCommentInfoCell" owner:self options:nil] lastObject];
        }
        if (infoDic.count>0) {
            infoCell.whole.text=[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"environment_score"]];
            infoCell.sever.text=[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"sercice_score"]];
            infoCell.level.text=[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"effect_score"]];
            
            float whole=[[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"overall_c"]] floatValue];
            if (whole>=0) {
                infoCell.wholeImageView.image=[UIImage imageNamed:@"公用_上箭头@2x.png"];
                infoCell.wholePeer.text=[NSString stringWithFormat:@"高于同行%.1f%%",whole*100];
                
            }else
            {
                infoCell.wholeImageView.image=[UIImage imageNamed:@"公用_下箭头@2x"];
                infoCell.wholePeer.text=[NSString stringWithFormat:@"低于同行%.1f%%",whole*(-100)];
            }
            
            float sever=[[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"attitude_c"]] floatValue];
            if (sever>=0) {
                infoCell.severImageView.image=[UIImage imageNamed:@"公用_上箭头@2x"];
                infoCell.severPeer.text=[NSString stringWithFormat:@"高于同行%.1f%%",sever*100];
                
            }else
            {
                infoCell.severImageView.image=[UIImage imageNamed:@"公用_下箭头@2x"];
                infoCell.severPeer.text=[NSString stringWithFormat:@"低于同行%.1f%%",sever*(-100)];
                
            }
            
            float level=[[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"effect_c"]] floatValue];
            if (level>=0) {
                infoCell.levelImageView.image=[UIImage imageNamed:@"公用_上箭头@2x"];
                infoCell.levelPeer.text=[NSString stringWithFormat:@"高于同行%.1f%%",level*100];
                
            }else
            {
                infoCell.levelImageView.image=[UIImage imageNamed:@"公用_下箭头@2x"];
                infoCell.levelPeer.text=[NSString stringWithFormat:@"低于同行%.1f%%",level*(-100)];
            }
            
        }
        return infoCell;
    }
    else
    {
        static NSString *inden=@"commentList";
        DocCommentListCell *listCell=[tableView dequeueReusableCellWithIdentifier:inden];
        if (!listCell) {
            listCell=[[[NSBundle mainBundle]loadNibNamed:@"DocCommentListCell" owner:self options:nil] lastObject];
        }
        return listCell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 115;
    }
    else return 74;
}
- (void)backClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}



@end
